<?php
/**
 * User: b179a9
 * Date: 10/12/11
 * Time: 9:37 PM 
 */
 
class Lib_Form_Validate_Nickname extends Zend_Validate_Abstract {

    const INVALID = 'invalidNick';

     /**
     * Message templates
     * @var array
     */
    protected $_messageTemplates = array(
        self::INVALID => 'Invalid nickname. It should consist of letters and numbers.'
    );

    /**
     * Returns true if and only if $value meets the validation requirements
     *
     * If $value fails validation, then this method returns false, and
     * getMessages() will return an array of messages that explain why the
     * validation failed.
     *
     * @param  mixed $value
     * @return boolean
     * @throws Zend_Validate_Exception If validation of $value is impossible
     */
    public function isValid($value)
    {
        if(!preg_match('/^[a-z0-9]+$/i', $value)) {
            $this->_error(self::INVALID);
            return false;
        }
        return true;
    }
}
